package liuwh.mina.basic.tcp.server.tiemserver.codec;

import java.nio.charset.Charset;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.textline.TextLineDecoder;
import org.apache.mina.filter.codec.textline.TextLineEncoder;

public class TimeResponseCodecFactory implements ProtocolCodecFactory {
	private ProtocolDecoder decoder;
	private ProtocolEncoder encoder;
	
	public TimeResponseCodecFactory(boolean server) {
		if(server) {
			decoder = new TextLineDecoder(Charset.forName("UTF-8"));
			encoder = new TimeResponseEncoder();
		} else {
			decoder = new TimeResponseDecoder();
			encoder = new TextLineEncoder(Charset.forName("UTF-8"));
		}
	}

	@Override
	public ProtocolDecoder getDecoder(IoSession session) throws Exception {
		return decoder;
	}

	@Override
	public ProtocolEncoder getEncoder(IoSession session) throws Exception {
		return encoder;
	}

}
